--
-- Author: ping.wang
-- Date: 2018-09-20 15:30:44
--
-- CrystalSocketRender
--

local ClassRef = app.mvc.createRenderClass(...)
local string_format = string.format
--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.WingSocketRender))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)
    self:setContentSize( self._ui.Panel:getContentSize() )
    self:refresh()
    display.uiAddClick(self._ui.Panel, function()
        if self._equipUid and self._data and self._data > 0 then
            executeFunc(self._onClick, "showCrystalOnEquipTips",{equipUid = self._equipUid, crystalId = self._data, render = self._ui.Panel})
        end

    end)
end

function ClassRef:refresh()
    if self._data then
        self:setVisible( true )

        local data = self._data
        local rockInfo = GD:queryRockById(data)
        local itemConf = GD:queryItemById(data)
        if rockInfo and itemConf then
            self._ui.grade:setVisible(true) --如果有宝石才需要显示
            self._ui.icon:setVisible(true) --宝石的icon
            self._ui.num:setVisible(true) --宝石+几的文字 几级就加几
            self._ui.num:setString(string_format("%d",tonumber(rockInfo.leve)))
            self._ui.num:setVisible(tonumber(rockInfo.leve) > 0)
            self._ui.icon:loadTexture(string.format("%s%s.png", Res.itemPath, itemConf.icon))
            self._ui.text:setVisible(false)
        else
            self._ui.grade:setVisible(false) --如果有宝石才需要显示
            self._ui.icon:setVisible(false) --宝石的icon
            self._ui.num:setVisible(false) --宝石+几的文字 几级就加几
            self._ui.text:setVisible(true)
        end
    else
        self:setVisible( false )
    end
end

function ClassRef:setEquipUid(uid)
    self._equipUid = uid
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
